home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1 / sys / msdos / ovlmgr.doc < prev    next >
Encoding:
Text File  |  1993-01-18  |  17.7 KB  |  394 lines

  1.     SCCS Id: @(#)ovlmgr.doc         3.1        91/02/02
  2.     Copyright (c) 1989, 1990, 1991, 1992, 1993 Pierre G Martineau and
  3.     Stephen P Spackman.  All Rights Reserved.
  4.     NetHack may be freely redistributed.  See license for details.
  5.          ====================================
  6.          Brief notes about ovlmgr.asm [v30a0]
  7.          ====================================
  8.                (revised 1991february02)
  9.  
  10. OVLMGR.ASM is a multiple-residency overlay manager for use with the
  11. Microsoft Overlay Linker.  It is functionally compatible with the one
  12. in the MSC library _except_:
  13.  
  14. - it usually accesses the disk less often and is a lot faster in some
  15.   applications.
  16. - it permits overlays to be stored in the .EXE file and/or in separate
  17.   .OVL files.
  18. - it has different tuning characteristics.
  19. - you must (of course) link OVLMGR.OBJ into the root overlay (that is,
  20.   outside any parentheses in the link command).
  21.  
  22. See also the notes below.
  23.  
  24.     As with other Microsoft-compatible overlay handlers you must
  25. be *very* careful never to call a function in an overlay through a
  26. pointer, unless the initiator of the call resides in the *same*
  27. physical overlay as the target (This is, of course, *not* the same
  28. thing as the called function being declared static, since the static
  29. declaration affects only the visibility of the name of the function,
  30. not the distribution of pointers to it.) (1).  Furthermore, setjmp()
  31. and longjmp() are not supported.
  32.  
  33.     Unlike the Microsoft system, most of the available memory is
  34. used to hold overlays.    Care must be taken to ensure that enough space
  35. is reserved for the C heap.  This can be accomplished through
  36. information stored in the .EXE file (currently the minalloc parameter,
  37. as described below).
  38.  
  39.     Furthermore, expanded memory support (EMS) is now an integral
  40. part of the overlay manager.  LIM EMS versions 3.2 and 4.0 are
  41. supported.  Note that the page frame must be 4 pages long (64K bytes) to
  42. be able to operate correctly (most drivers allocate a 64K frame by
  43. default).  The overlay manager will use as much EMS as is necessary in
  44. 64K chunks, up to a limit of 16 chunks (1 Meg).  Both hardware and
  45. software EMS drivers have been tested and found to be completely
  46. compatible.
  47.  
  48.     Starting with version 30a0, overlays are not restricted to
  49. being stored in the main .EXE files (as they are with Microsoft's
  50. overlay manager).  Using the utility EXESMURF arbitrary contiguous
  51. sequences of overlays can be unloaded into external overlay files.
  52. Although EXESMURF provides some flexibility in naming these files,
  53. OVLMGR presently only supports its default option, whereby the
  54. overlays of a programme PROGRAM.EXE must match the pattern
  55. PROGRAM?.OVL (if the basename had eight characters, as FILENAME.EXE,
  56. then the last character is replaced: FILENAM?.EXE) and reside in the
  57. *same* directory as the .EXE (not even a path search is performed).
  58. This mechanism permits large applications to be represented with small
  59. files, resulting in a slight performance improvement (due to less and
  60. shorter disk seeking) and easier transfer with floppy disks, at the
  61. cost of a heavier demand for file-handles.
  62.  
  63.                 ~ * ~
  64.  
  65.     OVLMGR.ASM currently has three assembly-time options, which are
  66. specified with the assembler's /D<symbol> option (or compatible).  They
  67. are:
  68.  
  69.     /DNOEMS   Disable EMS support.
  70.           OVLMGR normally detects the presence of EMS memory
  71.           and makes use of it whenever it is present.  This
  72.           flag instructs ovlmgr to ignore EMS and operate only
  73.           out of conventional memory.  It should be used when
  74.           overlaying programmes which expect to use EMS
  75.           themselves.
  76.  
  77.     /Di386      Use 80386-specific instruction sequences.
  78.           Use of this flag will make ovlmgr perform better on
  79.           machines with 80386 processors.  However, the
  80.           resulting programme will not run at all on machines
  81.           with less capable CPUs.  Use this option with
  82.           caution, especially in the case of distribution
  83.           code.
  84.  
  85.     /DNOSPLIT Do not provide for external .OVL files.
  86.           If this flag is NOT set, OVLMGR will look for
  87.           overlays for the programme PROGRAM.EXE in all files
  88.           matching the pattern PROGRAM?.OVL, as well as in the
  89.           .EXE file itself.  This arrangement may be slightly
  90.           faster and will result in more, smaller files, but
  91.           is obviously less robust, since mismatched .OVL
  92.           files can cause mayhem.  .OVL files can be generated
  93.           with our EXESMURF .EXE file manipulation utility.
  94.  
  95.                 ~ * ~
  96.  
  97.     Although using the overlay manager is in essence much like using
  98. Microsoft's, they operate on a slightly different principle, and tuning
  99. for them is rather different.  Technical part begins.
  100.  
  101.     When overlay linking is requested (see your linker manual), the
  102. MS overlay linker changes all far calls into overlays from the (normal,
  103. 8086) format:
  104.  
  105.     offset    contents
  106.     ------    --------
  107.     :0000    CALL
  108.     :0001    target-offset
  109.     :0003    target-segment
  110.  
  111. to this:
  112.     :0000    INT
  113.     :0001    int#    target-mod#
  114.     :0003    target-offset
  115.  
  116. (note that here we are looking at the actual layout of the machine
  117. code, not at the assembly code as such) and relocates the code parts
  118. of all the different overlays into the *same* physical area.  The
  119. overlaid code is all actually placed at the end of the .EXE file,
  120. after the 'normal' executable image, along with all its administrative
  121. data (fixups etc.).
  122.  
  123.     When this altered 'call' is executed, of course, the interrupt
  124. handler int# is invoked.  Its job is to ensure that the target overlay
  125. module is in memory (reading it from the tail of the .EXE file if it
  126. isn't already loaded) and then transfer to the given offset within it,
  127. 'faking up' the effect of the 'real' far call that would normally have
  128. occurred.  Something similar must be done when the call returns, to
  129. ensure that the thing being returned *into* is still (or is once more)
  130. loaded.
  131.  
  132.     The Microsoft linker, as we have said, relocates all the
  133. overlays to the same load address; and, in fact, it allocates am empty
  134. block of memory there that is at least as large as the largest
  135. overlay.  Into this area all the overlays are loaded without further
  136. change; thus, there can only ever be one overlay in memory at one
  137. time.  Transferring from one overlay to another causes one overlay to
  138. replace the other in the allocated overlay swap area.
  139.  
  140.     Our overlay manager does not use the space allocated by the
  141. linker in the same way.  Rather, it allocates almost all of the memory
  142. available from MS-DOS (including the original overlay area and any high
  143. DOS memory) as well as EMS memory if some is available and that option
  144. is being used.    As overlays are needed, they are loaded wherever they
  145. will fit, and dynamically relocated to that address.  Thus, many more
  146. than one overlay may be loaded at any given time, greatly increasing
  147. potential performance.    Management of space is more or less according to
  148. an LRU policy - once all of memory is full, the least recently used
  149. overlay is selected as the most likely candidate for replacement.
  150.  
  151.     The implications of this difference are as follows:  while with
  152. the conventional (default) overlay manager, the best strategy is to
  153. group object modules together in an overlay whenever they are known to
  154. be used in rapid succession, to make each overlay as big as possible
  155. (all things being equal) in order to take advantage of all available
  156. memory, and to make as few overlays as possible (to reduce the amount of
  157. disk access), the best strategy with our overlay manager is almost the
  158. reverse.  Having a lot of small overlays will increase the amount of
  159. useful stuff that can be resident in memory at the same time; all of
  160. memory will automatically be employed; and there is no advantage at all
  161. to uniformity of size (except perhaps in the unlikely case of *exact*
  162. uniformity!).
  163.  
  164.     Although ovlmgr allocates all available memory while it is
  165. active, you will find that the DOS exec() call works normally.    The
  166. memory that is allocated for administering the overlay system is freed
  167. before the exec call is made and reallocated afterwards (we trap the DOS
  168. function request vector to do this, which isn't very nice as a
  169. programming practise but makes the existence of the overlay manager far
  170. more transparent).  There is, however, one circumstance under which this
  171. can be problematic:  if you use the exec() call to load a TSR
  172. application, thereby causing memory that the overlay manager was using
  173. to become unavailable, you may make it impossible for the overlaid
  174. application to proceed.  This is because code that is nominally
  175. 'running' (i.e. is currently on the stack) cannot be relocated and must
  176. be reloaded at the *same address* that previously held it.  If another
  177. process now owns that area of memory, there is nothing we can do.  We
  178. believe that this should not be a serious concern in normal use.
  179.  
  180.                 ~ * ~
  181.  
  182.     Since all available memory is potentially used by ovlmgr, there
  183. is one additional concern in using it with C programmes:  the allocation
  184. of sufficient space for the C heap (2).  While previous versions of
  185. ovlmgr.asm required the change of an internal constant and re-assembly
  186. of ovlmgr to change the amount of space pre-allocated for this purpose,
  187. the current version uses the DOS minalloc parameter in the executable
  188. file to hold the size of the desired heap area.  This parameter can be
  189. set at any time after the link process with either Microsoft's exemod
  190. utility or with the supplied utility, exesmurf.
  191.  
  192.                 ~ * ~
  193.  
  194. NOTA BENE: This is an early version of the overlay manager, but by now
  195. it should be fairly well debugged. If you are considering upgrading it
  196. please be aware that the following improvements are planned for the
  197. next version (though who knows when delivery will occur):
  198.  
  199.       - compatible versions of setjmp() and longjmp()
  200.       - integral malloc() to eliminate the heap size guesswork
  201.       - support for swapped data areas (read-only and read/write)
  202.       - improved performance through dynamic link-loading (maybe)
  203.       - interlocking to permit floppy disk juggling use
  204.       - XMS support and improved EMS support
  205.       - support for divergent-functionality overlays (such as
  206.       hardware-specific modules)
  207.       - enabling the overlay locking code
  208.       - more flexibility in naming and locating external overlay files
  209.       - Major code revamping
  210.  
  211. Swap On!
  212.  
  213. ------------------------------------------------------------------------
  214. MESSAGES
  215.  
  216. OVLMGR: EMS memory manager error.
  217.  
  218.     An error occurred during an EMS access.  Either the hardware has
  219.     reported a bug, the software driver has detected an anomaly or
  220.     the page frame is not 64K bytes in length.
  221.  
  222. OVLMGR: Executable or overlay header missing or damaged.
  223.  
  224.     The end of a file was reached unexpectedly during
  225.     initialisation, while trying to locate the overlays.  This is a
  226.     very bad sign (though I am concerned that it might be triggered
  227.     spuriously by debug information or other non-executable tails on
  228.     files).
  229.  
  230. OVLMGR: File I/O error.
  231.  
  232.     An error occurred while trying to load an overlay.  We don't
  233.     want this.
  234.  
  235. OVLMGR: Inaccessible EXE file. Can't load overlays.
  236.  
  237.     For some reason ovlmgr could not locate or read the original
  238.     .EXE file in which the overlays reside.  This could be due to
  239.     your attempting to use a very old version of DOS,
  240.     an abject shortage of file handles, some strange event causing
  241.     the file to be deleted, a disk error, or the diskette that
  242.     contained the executable being removed.
  243.  
  244. OVLMGR: Inaccessible OVL file. Can't load overlays.
  245.  
  246.     An error was reported while attempting to open an .OVL file
  247.     which was expected (from its name) to contain external overlays.
  248.     The possible causes are similar to those of the previous
  249.     message.
  250.  
  251. OVLMGR: Incomplete executable.  OVL files missing?
  252.  
  253.     OVLMGR was unable to locate all of its overlays for some reason.
  254.     This could be due to I/O errors on the disk drive, but is more
  255.     likely caused by an external .OVL file not being present in the
  256.     same directory as the .EXE.
  257.  
  258. OVLMGR: Incorrect DOS version. Must be 3.00 or later.
  259.  
  260.     The current version of ovlmgr does not support versions of DOS
  261.     prior to 3.0 because of the difficulty of locating the
  262.     executable file (and hence the overlays) at runtime.
  263.  
  264. OVLMGR: Internal memory allocation failure.
  265.  
  266.     Either an internal error has occurred in ovlmgr or the
  267.     application programme, or some event has caused memory that
  268.     ovlmgr believed it could count on becoming unavailable.  A
  269.     typical example of the latter would be the result of
  270.     attempting to load a TSR while an overlaid application is
  271.     running.
  272.  
  273. OVLMGR: Not enough free memory left to run this program.
  274.  
  275.     Although DOS successfully loaded the programme, it proved
  276.     impossible to allocate enough additional contiguous memory to
  277.     load one or more of the overlays.  Either reduce the
  278.     RAM-loading of the application by reducing the size of either
  279.     the root or the largest overlays, or increase the amount of
  280.     memory available by unloading TSRs and/or simplifying your
  281.     CONFIG.SYS.
  282.  
  283. OVLMGR: Unable to resolve overlay file names.
  284.  
  285.     Apparently the name reported to OVLMGR as being that of the
  286.     executable file is ill-formed, and it is thus not possible to
  287.     intuit what external overlay files would be called.  It is
  288.     possible that this indicates that DOS has gone bonkers, but more
  289.     likely (I guess) that the .EXE was not invoked by DOS as we know
  290.     it.  Either way, you have entered the Twilight Zone....
  291.  
  292. (xxxx:xxxx:xxxx:xxxx)
  293.  
  294.     This is a diagnostic code composed of the following fields:
  295.         - error code
  296.         - version number
  297.         - available conventional memory
  298.         - EMS memory usage
  299.     Please note it in any bug reports or correspondence with the
  300.     development team.
  301.  
  302. ------------------------------------------------------------------------
  303. KNOWN BUGS
  304.  
  305. The present version cannot always be used as a direct replacement for
  306. Microsoft's overlay manager (even granted the documented differences)
  307. because the minimum size required for an overlaid programme to run is at
  308. least the size of the root plus TWICE the size of the largest overlay.
  309. If a programme has previously had its overlay structure tuned to take
  310. best advantage of Microsoft overlays, this may well cause a problem.
  311. The overlays themselves will need to be split up.
  312.  
  313. When the MicroSoft linker discovers that an overlay as requested
  314. contains NO instructions at all (this can happen by mistake if you give
  315. a source file that winds up holding only data declarations its own
  316. overlay), it does not emit an overlay record for it at all - there is
  317. simply a gap in the overlay sequence in the file.  The current version
  318. of OVLMGR detects this as an error, since it assumes that such a gap
  319. should have been filled by an external .OVL file.  It is presently your
  320. responsibility to ensure that this does not occur.
  321.  
  322. Files containing overlays are kept open all the time the application
  323. is running.  Particularly if multiple external .OVL files are used,
  324. this can result in less file handles being available to the user
  325. programme than would otherwise be expected.
  326.  
  327. ALL files that match the pattern for potential overlay files are
  328. opened, regardless of whether they actually contain overlays.
  329.  
  330. The names of external overlay files have a very restricted form, and
  331. they must reside in the same directory with the .EXE.  These
  332. limitations cause them to be useful for little else besides making
  333. distribution easier.
  334.  
  335. Transfers between overlays are very slow in machine terms, even if both
  336. overlays happen to reside in memory at the time (still significantly
  337. faster than Microsoft's, though).  This means that overlay patterns
  338. must be chosen on the basis of more than just logical dependency.
  339.  
  340. Locking overlays into memory is not really implemented even though
  341. reading the source code might make you think it was.  Actually, reading
  342. the source code itself isn't very well implemented right now.  Comments
  343. and stuff would help.  Yup, yup.
  344.  
  345. Due to limitations in the LIM EMS standard (to 4.0), programmes that
  346. themselves use EMS memory cannot be overlaid with ovlmgr unless ovlmgr's
  347. own EMS support is disabled.  This is accomplished by assembling with
  348. the /DNOEMS flag.
  349.  
  350. ------------------------------------------------------------------------
  351. BUG ALERT
  352.  
  353. To repeat a point made above, if you ever try to call a function in an
  354. overlay through a pointer, you *may* die with the Microsoft overlay
  355. manager.  If you ever try to call a function in an overlay through a
  356. pointer, you *will* die with ours.  Nothing in an overlay ever ends up
  357. in the same segment as the linker anticipated.    You have been warned!
  358.  
  359. ------------------------------------------------------------------------
  360. FOOTNOTES
  361.  
  362. (1) This problem can be circumvented through the use of surrogate
  363. 'trampoline' functions:  functions that reside in the root overlay and
  364. simply pass right through to the 'real', overlaid, implementations.
  365. This can even be made transparent to the source code through the use
  366. of the C macro preprocessor, with a locution of the form
  367.     #define foo(x) foo_(x)
  368. visible everywhere except at the actual definition point of the
  369. trampoline.  This method was implemented in NetHack 3.0, and remains today.
  370.  
  371. (2) If you should get a message to the effect that NetHack can't
  372. allocate 28000 and some bytes when entering a maze level, that
  373. isn't our problem!  In all probability you forgot to rebuild your
  374. special level files when you changed the compiler flags.  We got
  375. that one, too, at one point.  The same applies to similar messages when
  376. reading bones files or saved games:  it is more likely that you forgot
  377. to discard them after recompiling your game than that the memory
  378. allowance is so greatly incorrect.
  379.  
  380. ----------------------------------------------------------------------
  381. NOTICE
  382.  
  383. OVLMGR.ASM is brought to you by Pierre Martineau and Stephen Spackman.
  384. It, and this document, are copyright.  They are, however, provided as
  385. part of NetHack and may be freely distributed as described in the
  386. NetHack license.
  387.  
  388. ----------------------------------------------------------------------
  389. Stephen P Spackman                 stephen@tira.uchicago.edu
  390. Pierre G Martineau           pierre%ozrout.uucp@altitude.cam.org
  391. ----------------------------------------------------------------------
  392.     Copyright (c) 1989, 1990 Pierre G Martineau and Stephen P Spackman
  393.     All Rights Reserved.
  394.